package study.java.jdk.jdk8._3_comparator.comparing;

import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Test;
import study.java.jdk.jdk8.User1;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@Slf4j
public class _5_comparingDouble_Test {

    List<User1> src;

    @Before
    public void init() {
        User1 u1 = User1.builder().code("1").age(31).build();
        User1 u2 = User1.builder().code("1").age(36).build();
        src = Arrays.asList(u1, u2);
    }

    /**
     * （★）
     *
     * @param keyExtractor -Function: key提取器
     */
    @Test
    public void test1() {
        Collections.sort(src, Comparator.comparingDouble(User1::getAge));
        log.info("<<<<<< {}", src);
    }
}
